package com.koron.css2.newProjectCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.bean.PjPendingBean;
import com.koron.css2.newProjectCenter.bean.query.PjPendingQueryBean;
import com.koron.css2.newProjectCenter.mapper.PjPendingMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import com.koron.util.Tools;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.Map;

/**
 * 工程挂起详情查询
 */
public class PjPendingQuery implements ServerInterface {


    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            PjPendingQueryBean pjPendingQuery = JsonUtils.objectToPojo(req.getData(), PjPendingQueryBean.class);
            if (StringUtils.isBlank(pjPendingQuery.getId())){
                return MessageBean.create(Constant.MESSAGE_INT_FAIL,"id 不能为空",null);
            }
            PjPendingMapper pjPendingMapper = factory.getMapper(PjPendingMapper.class);

            // 1. 查询数据
            PjPendingBean pjPending = pjPendingMapper.selectById(pjPendingQuery.getId());
            if (StringUtils.isNotBlank(pjPending.getPjType())){
                Map<String, String> dicMap = Tools.mapDicByCode(factory, "PPT");
                pjPending.setPjTypeName(dicMap.get(pjPending.getPjType()));
            }

            // 2. 返回结果
            MessageBean<PjPendingBean> messageBean = MessageBean.create(Constant.MESSAGE_INT_SUCCESS,"工程挂起详情查询成功", PjPendingBean.class);
            messageBean.setData(pjPending);
            return messageBean;
        } catch (Exception e) {
            logger.error("工程挂起详情查询失败",e);
        }
        return MessageBean.create(Constant.MESSAGE_INT_FAIL,"工程挂起详情查询失败",null);
    }
}